package edu.pku.sei.mte.modification.command;

import edu.pku.sei.mte.constants.COMPOSITEMODE;
import edu.pku.sei.mte.mtemodel.metamodel.RTypeReference;
import edu.pku.sei.mte.mtemodel.model.MReference;

public class DeletingEdgeCommand extends ModelModificationCommand {
	
	private MReference delEdge;

	public MReference getDelEdge() {
		return delEdge;
	}

	public void setDelEdge(MReference delEdge) {
		this.delEdge = delEdge;
	}

	@Override
	public void execute() throws Exception {
		RTypeReference type = delEdge.getType();
		if(basicRemoveEdge(delEdge))
			commit();
		if(delEdge.getTarget()!=null && type.getEndComposite()==COMPOSITEMODE.SOURCE_COMPOSITE){
			removeNodeRequest(getModel(), delEdge.getTarget(), getContext());
		}
		if(delEdge.getSource()!=null && type.getEndComposite()==COMPOSITEMODE.TARGET_COMPOSITE){
			removeNodeRequest(getModel(), delEdge.getSource(), getContext());
		}
	}

	@Override
	public void undo() {
		basicAddEdge(delEdge);
	}
}
